/*
 * Path.cpp
 *
 *  Created on: Sep 21, 2009
 *      Author: jbarreneche
 */

#include "Path.h"

#include "exceptions/UnconnectedEdgeException.h"

namespace path {

Path::Path() {
}

Path::~Path() {
}

Path* Path::append(Edge* edge){
	if (!(this->canAppend(edge))) throw new UnconnectedEdgeException("El ultimo vertice no se corresponde con el primer vertice de la arista que se intenta concatenar");
	this->edges.append(edge);
	return this;
}
bool Path::canAppend(Edge* edge) {
	if (this->edges.isEmpty()) return true;

	Vertex* lastVertex = this->edges.get(this->edges.count() -1)->getDestination();
	return (lastVertex->equals(edge->getOrigin()));
}
Iterator Path::iterator() {
	return Iterator(this->edges.iterator());
}

}
